package com.waitingsnow.core.util.display
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.text.TextField;

/**
 * 
 * @author waitingsnow
 * $Id: DisplayUtil.as 2 2012-05-17 10:10:03Z cgslendy@gmail.com $
 */
public class DisplayUtil
{
	/**
	 * 获得指定长宽/背景颜色/背景透明度的sprite
	 * @param width
	 * @param height
	 * @param bgColor
	 * @param bgAlpha
	 * @return
	 *
	 */
	static public function getSp(width:int, height:int,
								 bgColor:uint = 0xCCCCCC, bgAlpha:Number = 1,
								 lineThick:int = 0,
								 lineColor:uint = 0x818181, lineAlpha:Number = 1):Sprite
	{
		var sp:Sprite = new Sprite();
		sp.graphics.clear();
		sp.graphics.lineStyle(lineThick, lineColor, lineAlpha);
		sp.graphics.beginFill(bgColor, bgAlpha);
		sp.graphics.drawRect(0, 0, width, height);
		sp.graphics.endFill();
		return sp;
	}
	
	/**
	 * 获取线框sprite
	 * @param width
	 * @param height
	 * @param lineColor
	 * @param lineAlpha
	 *
	 */
	static public function getLineSp(width:int, height:int,
									 lineThick:int = 0,
									 lineColor:uint = 0x818181,
									 lineAlpha:Number = 1):Sprite
	{
		var sp:Sprite = new Sprite();
		sp.graphics.clear();
		sp.graphics.lineStyle(lineThick, lineColor, lineAlpha);
		sp.graphics.drawRect(0, 0, width, height);
		sp.graphics.endFill();
		return sp;
	}
	
	/**
	 * 获得指定长宽/背景颜色/背景透明度的shape
	 * @param width
	 * @param height
	 * @param bgColor
	 * @param bgAlpha
	 * @return
	 *
	 */
	static public function getShape(width:int, height:int,
									bgColor:uint = 0xCCCCCC,
									bgAlpha:Number = 1,
									lineThick:int = 0,
									lineColor:uint = 0x818181, lineAlpha:Number = 1):Shape
	{
		var sp:Shape = new Shape();
		sp.graphics.clear();
		sp.graphics.lineStyle(lineThick, lineColor, lineAlpha);
		sp.graphics.beginFill(bgColor, bgAlpha);
		sp.graphics.drawRect(0, 0, width, height);
		sp.graphics.endFill();
		return sp;
	}
	
	/**
	 * 对指定显示元素添加背景图
	 * @param sp
	 * @param width
	 * @param height
	 * @param bgColor
	 * @param bgAlpha
	 * @param lineThick
	 * @param lineColor
	 * @param lineAlpha
	 *
	 */
	static public function setGraphics(sp:Sprite, width:int, height:int,
									   bgColor:uint = 0xCCCCCC, bgAlpha:Number = 1,
									   lineThick:int = 0,
									   lineColor:uint = 0x818181, lineAlpha:Number = 1):void
	{
		sp.graphics.clear();
		sp.graphics.lineStyle(lineThick, lineColor, lineAlpha);
		sp.graphics.beginFill(bgColor, bgAlpha);
		sp.graphics.drawRect(0, 0, width, height);
		sp.graphics.endFill();
	}
	
	/**
	 * 获取文本框
	 * @param x
	 * @param y
	 * @param width
	 * @param height
	 * @return
	 *
	 */
	static public function getTf(text:String = "", x:int = 0, y:int = 0,
								 width:int = 100, height:int = 20):TextField
	{
		var tf:TextField = new TextField();
		tf.x = x;
		tf.y = y;
		tf.width = width;
		tf.height = height;
		tf.text = text;
		tf.selectable = false;
		return tf;
	}
}
}